package com.example.app19_broadcastreceiver;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Toast;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

public class MainActivity extends AppCompatActivity {

    private static final String TAG = "MainActivity";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_main);
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });

        Log.i(TAG, "onCreate()");
    }

    /**
     * 发送一般广播
     * @param view view
     */
    public void sendNormalBroadcast(View view) {
        Intent intent = new Intent("com.example.app19_broadcastreceiver.MyBroadcastReceiver.Action");
        intent.putExtra("action", "hahaha");
        sendBroadcast(intent);
        Toast.makeText(this, "发送一般广播", Toast.LENGTH_SHORT).show();
    }

    /**
     * 发送有序广播
     * @param view view
     */
    public void sendOrderBroadcast(View view) {
        Intent intent = new Intent("com.example.app19_broadcastreceiver.MyBroadcastReceiver.Action2");
        intent.putExtra("action", "tatata");
        sendOrderedBroadcast(intent, null);
        Toast.makeText(this, "发送有序广播", Toast.LENGTH_SHORT).show();
    }
}